import request from '@/utils/request'
const path = 'http://39.108.248.115:9000'
const api = {
    // 预算条件
    budgets: path + '/budget/budgets',
    // 预算项目
    budgetProjects: path + '/budget/budgetProjects',
    // 预算项目类别
    cate: path + '/budget/budgetProjectCategories',
    // 填报预算项目数据
    projectData: path + '/budget/projectDatas/batch',
    // 接收上报的预算项目数据
    acceptProjectData: path + '/budget/projectDatas',

    // 指标
    indicators: path + '/budget/indicators',
    // 指标类别
    indicatorCate: path + '/budget/indicatorCategories',
    // 填报指标数据
    indicatorData: path + '/budget/indicatorDatas/batch',
    // 接收上报的指标数据
    acceptIndicatorDatas: path + '/budget/indicatorDatas',

    // 预算项目与指标关联
    associations: path + '/budget/associations',

    // 预算追踪
    trace: path + '/budget/trace',

    // 年度预算
    yearBudgets: path + '/budget/yearBudgets'
}

// 新增年度预算
export function addYearBudgets (parameter) {
    return request({
        url: api.yearBudgets,
        method: 'post',
        data: parameter
    })
}

// 更新年度预算
export function editYearBudgets (parameter) {
    return request({
        url: api.yearBudgets + '/' + parameter.budgetId,
        method: 'put',
        data: parameter
    })
}

// 导出Excel
export function getExportExcel (id) {
    return request({
        url: api.budgets + '/' + id + '/exportExcel',
        method: 'get',
        responseType: 'blob'
    })
}

// 导入预算项目
export function importExcel (parameter) {
    return request({
        url: api.budgetProjects + '/import',
        method: 'post',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data: parameter
    })
}

// 预算追踪导出Excel
export function getTraceExportExcel (parameter) {
    const par = '?storesId=' + parameter.storeId + '&storesDate=' + parameter.storesDate
    return request({
        url: api.trace + '/exportExcel' + par,
        method: 'get',
        responseType: 'blob'
    })
}

// 获取预算项目的关联指标
export function getTrace (parameter) {
    const par = '?storesId=' + parameter.storeId + '&storesDate=' + parameter.storesDate
    return request({
        url: api.trace + par,
        method: 'get'
    })
}

// 新增预算项目与指标关联
export function addAssociations (parameter) {
    return request({
        url: api.associations,
        method: 'post',
        data: parameter
    })
}

// 更新预算项目与指标关联
export function editAssociations (parameter) {
    return request({
        url: api.associations,
        method: 'put',
        data: parameter
    })
}

// 删除预算项目与指标关联
export function deleteAssociations (id) {
    return request({
        url: api.associations + '/' + id,
        method: 'delete'
    })
}
// 获取预算项目的关联指标
export function detailAssociations (id) {
    return request({
        url: api.associations + '/' + id,
        method: 'get'
    })
}

// 填报预算项目数据
export function addProjectData (parameter) {
    return request({
        url: api.projectData,
        method: 'post',
        data: parameter
    })
}
// 填报指标数据
export function addIndicatorData (parameter) {
    return request({
        url: api.indicatorData,
        method: 'post',
        data: parameter
    })
}

// 接收上报的预算项目数据
export function acceptProjectData (parameter) {
    return request({
        url: api.acceptProjectData,
        method: 'post',
        data: parameter
    })
}
// 接收上报的指标数据
export function acceptIndicatorData (parameter) {
    return request({
        url: api.acceptIndicatorDatas,
        method: 'post',
        data: parameter
    })
}

// 预算条件分页查询
export function getBudgets (parameter) {
    const par = '?pageNum=' + parameter.current + '&pageSize=' + parameter.pageSize +
        '&type=' + parameter.type + '&archived=' + parameter.archived +
        '&states=' + parameter.states + '&beginDate=' + parameter.beginDate +
        '&endDate=' + parameter.endDate + '&storeId=' + parameter.storeId
    return request({
        url: api.budgets + par,
        method: 'get'
    })
}
// 发起预算
export function getBudgetsLaunch (parameter) {
    const par = '?type=' + parameter.type + '&budgetDate=' + parameter.budgetDate +
        '&storeId=' + parameter.storeId
    return request({
        url: api.budgets + '/0/launch' + par,
        method: 'get'
    })
}
// 审核预算
export function putBudgetsApproval (parameter) {
    return request({
        url: api.budgets + '/' + parameter.budgetId + '/approval',
        method: 'put',
        data: parameter
    })
}
// 提交预算
export function submitBudgets (parameter) {
    return request({
        url: api.budgets + '/' + parameter.budgetId + '/submit',
        method: 'put',
        data: parameter
    })
}
// 新增预算
export function addBudgets (parameter) {
    return request({
        url: api.budgets,
        method: 'post',
        data: parameter
    })
}
// 修改预算
export function editBudgets (parameter) {
    return request({
        url: api.budgets + '/' + parameter.budgetId,
        method: 'put',
        data: parameter
    })
}
// 删除预算
export function deleteBudgets (parameter) {
    return request({
        url: api.budgets + '/' + parameter.budgetId + '/delete',
        method: 'put',
        data: parameter
    })
}
// 预算详情
export function detailBudgets (budgetId) {
    return request({
        url: api.budgets + '/' + budgetId,
        method: 'get'
    })
}

// 预算项目查询
export function getProjects (parameter) {
    const par = '?pageNum=' + parameter.current + '&pageSize=' + parameter.pageSize +
        '&categoryId=' + parameter.categoryId + '&name=' + parameter.name +
        '&description=' + parameter.description + '&inOrOut=' + parameter.inOrOut
    return request({
        url: api.budgetProjects + par,
        method: 'get'
    })
}
// 新增预算项目
export function addProjects (parameter) {
    return request({
        url: api.budgetProjects,
        method: 'post',
        data: parameter
    })
}
// 修改预算项目
export function editProjects (parameter) {
    return request({
        url: api.budgetProjects + '/' + parameter.projectId,
        method: 'put',
        data: parameter
    })
}
// 删除预算项目
export function deleteProjects (id) {
    return request({
        url: api.budgetProjects + '/' + id,
        method: 'delete'
    })
}

// 查询预算项目类别
export function getProjectCate () {
    return request({
        url: api.cate,
        method: 'get'
    })
}

// 新增预算项目类别
export function addProjectCate (parameter) {
    return request({
        url: api.cate,
        method: 'post',
        data: parameter
    })
}

// 修改预算项目类别
export function editProjectCate (parameter) {
    return request({
        url: api.cate + '/' + parameter.categoryId,
        method: 'put',
        data: parameter
    })
}
// 删除预算项目类别
export function deleteProjectCate (id) {
    return request({
        url: api.cate + '/' + id,
        method: 'delete'
    })
}

// 查询指标类别
export function getCateIndicator () {
    return request({
        url: api.indicatorCate,
        method: 'get'
    })
}

// 新增指标类别
export function addCateIndicator (parameter) {
    return request({
        url: api.indicatorCate,
        method: 'post',
        data: parameter
    })
}

// 修改指标类别
export function editCateIndicator (parameter) {
    return request({
        url: api.indicatorCate + '/' + parameter.categoryId,
        method: 'put',
        data: parameter
    })
}
// 删除指标类别
export function deleteCateIndicator (id) {
    return request({
        url: api.indicatorCate + '/' + id,
        method: 'delete'
    })
}

// 指标查询
export function getIndicators (parameter) {
    const par = '?pageNum=' + parameter.current + '&pageSize=' + parameter.pageSize +
        '&categoryId=' + parameter.categoryId + '&name=' + parameter.name +
        '&code=' + parameter.code + '&description=' + parameter.description +
        '&inOrOut=' + parameter.inOrOut + '&valueType=' + parameter.valueType
    return request({
        url: api.indicators + par,
        method: 'get'
    })
}
// 新增指标
export function addIndicators (parameter) {
    return request({
        url: api.indicators,
        method: 'post',
        data: parameter
    })
}
// 修改指标
export function editIndicators (parameter) {
    return request({
        url: api.indicators + '/' + parameter.indicatorId,
        method: 'put',
        data: parameter
    })
}
// 删除指标
export function deleteIndicators (id) {
    return request({
        url: api.indicators + '/' + id,
        method: 'delete'
    })
}
